home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2000 October / Macworld CD 17.10.iso / pc / Data / Shareware / Utilities / KeyQuencer Lite 2.5.5 Installer / Developer Toolkit / Extension sample code / Action.c next >
Encoding:
Text File  |  1997-09-29  |  3.5 KB  |  84 lines  |  [TEXT/CWIE]

  1. //==============================================================================
  2. // KEYQUENCER EXTENSION SAMPLE - VERSION 2.1 - MARCH 1997
  3. // By Alessandro Levi Montalcini <alm@torino.alpcom.it>
  4. // ©1994-97 Binary Software, Inc. <http://www.binarysoft.com>
  5. // Don’t forget to send us any cool extensions you create!
  6. // This text looks best in monaco 9 font, 4 spaces per tab, no wrapping
  7. //==============================================================================
  8. // DOCUMENTATION IS AVAILABLE IN THE EXTENSION.H AND ACTION.H HEADERS
  9. //==============================================================================
  10.  
  11. #include "Extension.h"
  12. #include "Action.h"
  13.  
  14. Handle    gTextResource;
  15.  
  16. //==============================================================================
  17. // THIS ROUTINE IS CALLED WHEN THE EXTENSION IS INVOKED BY A MACRO
  18.  
  19. short run(ParamsPtr params, MachineHandle mac, GluePtr glue)
  20. {
  21.     // This is where the extension does its work
  22.     // cur heap zone = active app heap, cur res file = unknown
  23.     // the extension file is closed, resources are not available
  24.     
  25.     StringPtr    string;
  26.     long        length;
  27.     short        index;
  28.     Str255        message;
  29.     
  30.     if(glue->glueRecVers<kCurGlueRecVers)                                // the IsLiteralParameter callback
  31.         return kTellObsoleteKeyQuencer;                                    // requires KQ 2.0, make sure we have it
  32.     message[0] = 0;                                                        // clear message string
  33.     for(index=0; index<params->paramsCount; ++index)                    // scan all params
  34.     {
  35.         string = params->parameter[index];                                // get nth parameter
  36.         if(message[0]==0                                                // we only accept one parameter
  37.         &&(*glue->IsLiteralParameter)(string, message, 255))            // check for quoted parameter
  38.         {
  39.             // do nothing here, IsLiteralParameter already copied
  40.             // the parameter to the "message" local variable
  41.         }
  42.         else if(EqualString("\pLOADED", string, false, true))            // check for "loaded" keyword
  43.         {
  44.             if(message[0]>0) return kTellTooManyParams;                    // again, no more than 1 param
  45.             if(gTextResource==0L)                                        // 'TEXT' 128 not found
  46.             {
  47.                 (*glue->DisplayMessage)("\ptext resource not found at startup.", true);
  48.                 return kExtGenericError;
  49.             }
  50.             length = GetHandleSize(gTextResource);                        // get text length
  51.             if(length>255) length = 255;                                // max length of our string
  52.             BlockMoveData(*gTextResource, &message[1], length);            // copy to message string
  53.             message[0] = (unsigned char)length;
  54.         }
  55.         else return kTellUnknownKeyword;                                // unknown keyword found
  56.     }
  57.     if(message[0]==0) return kTellNotEnoughParams;                        // didn't find required parameter
  58.     
  59.     (*glue->DisplayMessage)(message, false);                            // display our message
  60.     return kExtNoError;                                                    // we're done
  61. }
  62.  
  63. //==============================================================================
  64. // THIS ROUTINE IS CALLED ONCE AT STARTUP TIME
  65.  
  66. short init(ParamsPtr params, MachineHandle mac, GluePtr glue)
  67. {
  68.     // This is only called once at startup time
  69.     // cur heap zone = sys heap, cur res file = extension res file
  70.     // you may load (and detach) resources and initialize your data
  71.     // glue is only available in recent versions, check for nil glue
  72.     
  73.     gTextResource = Get1Resource('TEXT', 128);                            // load resource
  74.     if(gTextResource)
  75.     {
  76.         HNoPurge(gTextResource);                                        // make it unpurgeable
  77.         DetachResource(gTextResource);                                    // res file will be closed soon
  78.     }
  79.     if(glue) (*glue->ShowStartupIcon)(128);                                // show our own icon (no glue was available in KQ 1.0)
  80.     return kExtNoError;                                                    // everything OK
  81. }
  82.  
  83. //==============================================================================
  84.